package com.base.data.elasticsearch.util;

import org.apache.http.Header;
import org.apache.http.HttpEntity;
import org.elasticsearch.client.*;

import java.io.IOException;
import java.util.Map;

/**
 * 解决查询 http req/resp bufferLimit
 */
public class MiddleLevelRestClient {
    RestClient restClient;

    private int bufferLimit;

    public MiddleLevelRestClient(RestClient restClient) {
        this.restClient = restClient;
    }

    public MiddleLevelRestClient(RestClient restClient, int bufferLimit) {
        this.restClient = restClient;
        this.bufferLimit = bufferLimit;
    }

    public Response performRequest(String method, String endpoint, Map<String, String> params,
                                   HttpEntity entity, Header... headers) throws IOException {
        return restClient.performRequest(method, endpoint, params, entity, HttpAsyncResponseConsumerFactoryUtil.getFactory( bufferLimit), headers);
    }

    public void performRequestAsync(String method, String endpoint, Map<String, String> parameters, HttpEntity entity, ResponseListener responseListener, Header[] headers) {
        restClient.performRequestAsync(method, endpoint, parameters, entity, HttpAsyncResponseConsumerFactoryUtil.getFactory( bufferLimit), responseListener, headers);
    }
}
